package youleche.com.controler.controler;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import youleche.com.business.BShare;
import youleche.com.controler.servlet.common.UlecheHttpServlet;
import youleche.com.model.MShare;

/**
 * Servlet implementation class ShareUrlForwardController
 */
public class ShareUrlForwardController extends UlecheHttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShareUrlForwardController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String url = request.getRequestURI();
		String[] urlArray = url.split("\\/");
		if(urlArray!= null && urlArray.length > 1){
			BShare handler = new BShare();
			try {
				MShare share = handler.getShareById(urlArray[urlArray.length - 1].split("\\.")[0]);
				if(share != null){
					request.setAttribute("title", share.getTitle());	
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			request.setAttribute("html", "html/" + urlArray[urlArray.length - 1]);
			request.getRequestDispatcher("/qy/detail.jsp").forward(request, response);
		}
	}

}
